<!DOCTYPE html>
<html>

<head>
	<title>小水滴</title>
	<meta name="keywords"  />
	<meta name="description" content="" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
	<!-- Custom Theme files 1280*559-->
  	<link href="/static/js/layui/css/layui.css" rel="stylesheet">
	<link href="/static/js/layui/css/form.css" rel="stylesheet">
	<!-- //Custom Theme files -->
	<!-- 青、赤、黄、白、黑 -->
  	<script src="/static/js/layui/layui.js"></script>
  	<script src="/static/js/common.js"></script>
</head>

<body class="body-page">
	<div class="search layui-form" lay-filter="search">
		<div class="form-table">
			<div class="form-row">
				<div class="form-cell">
					<label>归属</label>
				</div>
				<div class="form-cell">
					<select name="gs" lay-filter="gs" lay-search="" lay-verify=""></select>
				</div>
				<div class="form-cell">
					<label>名称</label>
				</div>
				<div class="form-cell">
					<input type="text" name="name" lay-affix="clear" lay-verify="required" lay-vertype="tips" placeholder="请输入名称" autocomplete="off" class="layui-input">
				</div>
				<div class="form-cell">
					<button class="layui-btn layui-btn-sm" id="search">搜索</button>
					<button class="layui-btn layui-btn-sm" id="create">新增</button>
				</div>
			</div>
		</div>
	</div>
	<div class="grid">
		<table class="layui-hide" id="table" lay-filter="table"></table>
	</div>
</body>
<script>
	var tableId = 'table'+c.uuid();
	var editArea = ['1000px', '500px'];

	$(function(){
		c.table({
			elem: '#table',
			url: '/user/page',
			id:tableId,
			height: 'full',
			cellMinWidth: 80,
			page: true,
			cols: [[
				{field:'name',title: '姓名',width:180},
				{field:'code',title: '域账号',width:180},
				{field:'gs',title: '归属',width:180,templet:function(row){
					var bbz = '';
					if( row.gs == 1 ){
						bbz = '项目组';
					}else if( row.gs == 2 ){
						bbz = '非项目组';
					}
					return bbz;
				}},
				{field:'bz',title: '编制',width:180,templet:function(row){
					var bbz = '';
					if( row.bz == 1 ){
						bbz = '正编';
					}else if( row.bz == 2 ){
						bbz = '百得自有';
					}else if( row.bz == 3 ){
						bbz = '百得外包';
					}else if( row.bz == 5 ){
						bbz = '其他外包';
					}
					return bbz;
				}},
				{field:'role',title: '角色',width:180,templet:function(row){
					var bbz = '';
					if( row.role == 100 ){
						bbz = 'admin';
					}else if( row.role == 1 ){
						bbz = '产品';
					}else if( row.role == 2 ){
						bbz = '后端';
					}else if( row.role == 3 ){
						bbz = '前端';
					}else if( row.role == 5 ){
						bbz = '测试';
					}else if( row.role == 6 ){
						bbz = '运维';
					}else if( row.role == 7 ){
						bbz = '项目经理';
					}
					return bbz;
				}},
				{field:'op',title: '操作',width:180,templet:function(row){
					var edit = '<a href="javascript:editRow(&apos;'+row.id+'&apos;);" class="bluea">编辑</a>';
					var del = '<a href="javascript:deleteRow(&apos;'+row.id+'&apos;);" class="reda">删除</a>';
					return edit+c.opSpace()+del;
				}}
			]],
			error: function(res, msg){
				console.log(res, msg)
			}
		});

		$('#create').click(function(){
			c.window({
				area: editArea,
				content:'/html/user_add.html'
			});
		});

		$('#search').click(function(){
			reloadTable({where:c.putPrefix(form.val('search'),'user.')});
		});

		loadGs();
	});

	function loadGs(){
		var ele = $('select[name="gs"]');
		var list = [{id:1,name:'项目组'},{id:2,name:'非项目组'}];
		ele.empty();
		ele.append('<option value="">请选择或搜索</option>');
		for( var i=0 ; i<list.length ; i++ ){
			var row = list[i];
			ele.append('<option value="'+row.id+'">'+row.name+'</option>');
		}
		form.render(ele);
	}

	function reloadTable(queryParams){
		queryParams = queryParams ? queryParams : {};
		table.reloadData(tableId,queryParams,true);
	}

	function editRow(id){
		c.window({
			area: editArea,
			content:'/html/user_add.html?id='+id
		});
	}

	function deleteRow(id){
    	layer.confirm('确定要删除吗？', {icon: 3, title:'提示'}, function(index){
			c.request('user/delete',{id:id},function(resp){
				if( resp.code == 200 ){
					c.message('删除成功');
				}else{
					c.message(resp.message);
				}
				reloadTable();
			});
			layer.close(index);
		});
	}

	
</script>
</html>